import 'package:fluttertest/models/delivery_item.dart';
import 'package:json_annotation/json_annotation.dart';

@JsonSerializable()
class RouteModel {
   Sequence? current;
   Sequence? next;
   List<Sequence> steps;
   bool over;


  RouteModel({
    this.current,
    this.next,
    required this.steps,
    required this.over,
  });

  factory RouteModel.fromJson(Map<String, dynamic> json) {
    return RouteModel(
      current: json['current'] != null ? Sequence.fromJson(json['current']) : null,
      next:json['next'] != null?Sequence.fromJson(json['next']):null,
      steps: (json['steps'] as List<dynamic>?)
          ?.map((step) => Sequence.fromJson(step))
          .toList() ?? [],
      over: json['over'] ?? false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'current': current?.toJson(),
      'next': next?.toJson(),
      'steps': steps.map((step) => step.toJson()).toList(),
      'over': over,
    };
  }
}

@JsonSerializable()
class Sequence {
  final int id;
  final String waybillNumber;
  final String storeNumber;
  final String storeName;
  final int index;
  final String estimateArrivalTime;
  final String actualArrivalTime;
  final String leaveStoreTime;
  final int status;
  final int unArrival;
   String remark;
  final String createTime;
   int emptyTrunBox;
   int realEmptyTrunBox;
  final String shippingOrderNumber;
  final int completeCount;
  int realCompleteCount;
  final int trunBox;
   int realTrunBox;
  final int tagCount;
   int realTagCount;
  final int prizeGoodCount;
  final String loadingNumber;
  final String fangsunJobNumber;
  final String fadadaSignUrl;
   int fadadaStatus;
  final String fadadaId;
  final String taskno;
  final String sendoutbillno;
   String skipShopPic;
  final String phonecode;
  final int recboxamount;
  final int applylabelcount;
  final int changelabelcount;
  final int newlabelcount;
  List<DeliveryItem> otherDetails;
  bool isExpanded = false;
  

  Sequence({
    required this.id,
    required this.waybillNumber,
    required this.storeNumber,
    required this.storeName,
    required this.index,
    required this.estimateArrivalTime,
    required this.actualArrivalTime,
    required this.leaveStoreTime,
    required this.status,
    required this.unArrival,
    required this.remark,
    required this.createTime,
    required this.emptyTrunBox,
    required this.realEmptyTrunBox,
    required this.shippingOrderNumber,
    required this.completeCount,
    required this.realCompleteCount,
    required this.trunBox,
    required this.realTrunBox,
    required this.tagCount,
    required this.realTagCount,
    required this.prizeGoodCount,
    required this.loadingNumber,
    required this.fangsunJobNumber,
    required this.fadadaSignUrl,
    required this.fadadaId,
    required this.fadadaStatus,
    required this.taskno,
    required this.sendoutbillno,
    required this.skipShopPic,
    required this.phonecode,
    required this.recboxamount,
    required this.applylabelcount,
    required this.changelabelcount,
    required this.newlabelcount,
    required this.otherDetails,
    this.isExpanded = false

  });

  factory Sequence.fromJson(Map<String, dynamic> json) {
    return Sequence(
      id: json['id'] ?? 0,
      waybillNumber: json['waybillNumber']??'' ,
      storeNumber: json['storeNumber']??'' ,
      storeName: json['storeName'] ,
      index: json['index'] ,
      estimateArrivalTime: json['estimateArrivalTime'] ?? '',
      actualArrivalTime: json['actualArrivalTime'] ?? '',
      leaveStoreTime: json['leaveStoreTime'] ?? '',
      status: json['status'] ??0,
      unArrival: json['unArrival']??0,
      remark: json['remark'] ?? '',
      createTime: json['createTime'] ?? '',
      emptyTrunBox: json['emptyTrunBox'] ?? 0,
      realEmptyTrunBox: json['realEmptyTrunBox'] ?? 0,
      shippingOrderNumber: json['shippingOrderNumber'] ?? '',
      completeCount: json['completeCount'] ,
      realCompleteCount: json['realCompleteCount'] ,
      trunBox: json['trunBox'] ,
      realTrunBox: json['realTrunBox'] ,
      tagCount: json['tagCount'] ,
      realTagCount: json['realTagCount'] ,
      prizeGoodCount: json['prizeGoodCount'] ?? 0,
      loadingNumber: json['loadingNumber'] ,
      fangsunJobNumber: json['fangsunJobNumber'] ?? '',
      fadadaSignUrl: json['fadadaSignUrl'] ?? '',
      fadadaId: json['fadadaId'] ?? '',
      fadadaStatus: json['fadadaStatus'] ?? 0,
      taskno: json['taskno'] ?? '',
      sendoutbillno: json['sendoutbillno'] ?? '',
      skipShopPic: json['skipShopPic'] ?? '',
      phonecode: json['phonecode'] ?? '',
      recboxamount: json['recboxamount'] ?? 0,
      applylabelcount: json['applylabelcount'] ?? 0,
      changelabelcount: json['changelabelcount'] ?? 0,
      newlabelcount: json['newlabelcount'] ?? 0,
      otherDetails: (json['otherDetails'] as List<dynamic>?)
        ?.map((step) => DeliveryItem.fromJson(step))
        .toList() ?? []
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'waybillNumber': waybillNumber,
      'storeNumber':storeNumber,
      'storeName': storeName,
      'index': index,
      'estimateArrivalTime':estimateArrivalTime,
      'actualArrivalTime': actualArrivalTime,
      'leaveStoreTime':leaveStoreTime,
      'status': status,
      'unArrival': unArrival,
      'remark': remark,
      'createTime':createTime,
      'emptyTrunBox': emptyTrunBox,
      'realEmptyTrunBox': realEmptyTrunBox,
      'shippingOrderNumber': shippingOrderNumber,
      'completeCount':completeCount,
      'realCompleteCount': realCompleteCount,
      'trunBox': trunBox,
      'realTrunBox': realTrunBox,
      'tagCount': tagCount,
      'realTagCount':realTagCount,
      'prizeGoodCount': prizeGoodCount,
      'loadingNumber':loadingNumber,
      'fangsunJobNumber': fangsunJobNumber,
      'fadadaSignUrl': fadadaSignUrl,
      'fadadaId': fadadaId,
      'fadadaStatus': fadadaStatus,
      'taskno': taskno,
      'sendoutbillno': sendoutbillno,
      'skipShopPic':skipShopPic,
      'phonecode': phonecode,
      'recboxamount': recboxamount,
      'applylabelcount': applylabelcount,
      'changelabelcount': changelabelcount,
      'newlabelcount': newlabelcount,
    };
  }
}